<template>
  <div class="market_index">

    <div class="header">
      <button>
        <router-link to="Market_search"><span class="glyphicon glyphicon-search	"></span>搜索商品</router-link>
      </button>
    </div>
    <div class="aside_left">
      <nav>
        <ul>
          <li v-bind:class="{'bgc_whitesmoke': item['category_name'] == show_cate }" v-for="item of market_result"
              @click="cateFirst(item)">{{item["category_name"]}}
          </li>
        </ul>
      </nav>
    </div>
    <div class="market_content" v-show="item['category_name'] == show_cate " v-for="item of market_result">
      <div class="market_banner">
        <img v-bind:src="item['image_url']" alt="您的网络异常"/>
      </div>
      <menu>
        <ul>
          <li v-for="child of item['child_categories']">
            <dl>
              <dt>{{child["category_name"]}}</dt>
              <dd>
                <a @click="to_result()" v-for="grandchild of child['child_categories']"
                   v-if="grandchild['category_name']">
                  <img v-if="grandchild['image_url']" v-bind:src="grandchild['image_url']" alt=""/>
                  <label>{{grandchild["category_name"]}}</label>
                </a>
              </dd>
            </dl>
          </li>
        </ul>
      </menu>
    </div>
  </div>
</template>

<script>
  import jquery from "jquery"
  export default {
    name: 'market_index',
    data: function () {
      return {
        msg: 'market_index',
        apiUrl: "../../../static/market_index.json",
        market_result: [],
        show_cate: "一键选酒",
      }
    },
    created: function () {
      this.$http.get(this.apiUrl)
        .then(function (res) {
          this.market_result = res["body"]["result"];
          console.log(this.market_result)
        })
        .catch(function (err) {
          console.log(err)
        })
    },
    methods: {
      toSearch: function () {
        console.log(1)
      },
      to_result: function () {
        console.log(2);
        this.$router.push({path:"Market_result"})
      },
      cateFirst: function (item) {
        this.show_cate = item["category_name"]
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
  .market_index {
  overflow: hidden;
  background-color: whitesmoke;
  height: 100%;
}

.header {
  position: fixed;
  top: 0;
  width: 100%;
  padding: 0.15rem;
  height: 1.15rem;
  text-align: center;
  background: white;
  box-shadow: 0 1px 3px grey;
  button {
    background: whitesmoke;
    border: 1px solid lightgrey;
    line-height: 0.75rem;
    font-size: 0.35rem;
    padding-top: 0.05rem;
    border-radius: 0.2rem;
    width: 95%;
    a {
      display: block;
      width: 100%;
      color: grey;
      span {
        padding-right: 0.1rem;
      }
    }
  }
}

.aside_left {
  width: 25%;
  height: 100%;
  background: white;
  float: left;
  overflow: hidden;
  nav {
    ul {
      li {
        background: white;
        border-bottom: 1px solid lightgrey;
        line-height: 1.83rem;
        font-size: 0.4rem;
        text-align: center;
      }
      .bgc_whitesmoke{
        background: whitesmoke;
        color: darkred;
      }
    }
  }
}

.market_content {
  width: 72%;
  height: 100%;
  margin-top: 0.2rem;
  float: right;
  background: whitesmoke;
  overflow: auto;
  position: relative;
  .market_banner {
    width: 100%;

    background: grey;
    img {
      width: 100%;
      display: block;
    }
  }
  menu {

    ul {

      li {

        dl {

          dt {
            padding-top: 0.5rem;
            padding-bottom: 0.2rem;
            font-size: 0.35rem;
            font-weight: 400;
          }
          dd {
            padding: 0.3rem 0;
            background: white;
            display: block;
            &:after {
              clear: both;
              content: "";
              height: 0;
              visibility: visible;
              display: block;
            }
            a {
              float: left;
              display: block;
              width: 33%;
              img {
                display: block;
                margin: 0.2rem auto 0.3rem;
                width: 1.0rem;
                height: 1.15rem;
              }
              label {
                width: 85%;
                text-overflow: ellipsis;
                text-align: center;
                display: block;
                line-height: 2.2em;
                margin: auto;
                height: 2.2em;
                overflow: hidden;
                white-space: nowrap;
                color: grey;
                font-size: 0.35rem;
                font-weight: 400;
              }
            }
            a:nth-child(-n+3) {
              label {
                color: darkred;
              }
            }
          }

        }
      }
      li:last-child {
        dd {
          padding-bottom: 1rem;
        }
      }
    }
  }
}



</style>
